class IDGen:
    startID = 1
    def __init__(self):
        self.ValidIDPool = []
        self.InvalidIDPool = []

    def MaxIDSlotSet(self, value):
        self.ValidIDPool = range(IDGen.startID,value+IDGen.startID)
        self.InvalidIDPool = []

    def HasValidID(self):
        ret = len(self.ValidIDPool) > 0
        return ret

    def IDPick(self):
        # raise exception when self.ValidIDPool is empty
        id = self.ValidIDPool.pop(0)
        return id

    def IDRelease(self, id):
        self.ValidIDPool.append(id)

    def CloseIDSlot(self):
        # make sure there has id in ValidIDPool
        self.InvalidIDPool.append(self.ValidIDPool.pop())

    def OpenIDSlot(self):
        # make sure there has id in InvalidIDPool
        self.ValidIDPool.append(self.InvalidIDPool.pop(0))

    def __repr__(self):
        ret = """\
ValidIDPool = %s
InvalidIDPool = %s"""%(self.ValidIDPool,self.InvalidIDPool)
        return ret
